package com.ly.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectConfiguration {

    /**
     * 声明交换机
     * @return Direct 直连/订阅 交换机
     */
    @Bean
    public DirectExchange directExchange(){
//        return ExchangeBuilder.directExchange("linyu.direct").build();
        return new  DirectExchange("linyu.direct");
    }

    /**
     * 第一个队列
     * @return
     */
    @Bean
    public Queue directQueue1(){
        return new Queue("direct.queue1");
    }

    /**
     * 绑定队列和交换机
     * @param directQueue1
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingQueue1WithRed(Queue directQueue1,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue1).to(directExchange).with("red");
    }

    /**
     * 绑定队列和交换机
     * @param directQueue1
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingQueue1WithBlue(Queue directQueue1,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue1).to(directExchange).with("blue");
    }

    /**
     * 第二个队列
     * @return
     */
    @Bean
    public Queue directQueue2(){
        return new Queue("direct.queue2");
    }

    /**
     * 绑定队列和交换机
     * @param directQueue2
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingQueue2WithRed(Queue directQueue2,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue2).to(directExchange).with("red");
    }

    /**
     * 绑定队列和交换机
     * @param directQueue2
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingQueue2WithYellow(Queue directQueue2,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue2).to(directExchange).with("yellow");
    }

}
